'''
Created on 17/10/2011

@author: nacho
'''

from operatingSystem import OperatingSystem
from scheduler import Scheduler
from memory import Memory
from ioinstruction import IOInstruction
from planFIFO import FIFO
from program import Program
from cpuInstruction import CPUInstruction
from planPriority import Priority
from timer import Timer
from planRoundRobin import RoundRobin
from mmu import MMU
from assignationBestAdjustment import BestAdjustment
from assignationFirstAdjustment import FirstAdjustment
from assignationWorstAdjustment import WorstAdjustment
from pagination import Pagination
from page import Page
from assignation import Assignation
from printingInstruction import PrintInstruction
from pruebaDeInstruccion import PruebaInstruction



if __name__ == '__main__':
    
    
    
    def printeable(cpu, str = "Higher"):
        
        print(str)
        
    def printeable2(cpu):
        
        print("Order")
        
        
    def defineVariable1(cpu):
        
        cpu.setVariable("x", 5)
        print("X variable setted")
        
    def defineVariable2(cpu):
        
        cpu.setVariable("y", 6)
        print("Y variable setted")
        
        
    def getVariableResult(cpu):
        
        x = cpu.getVariable("z")
        print(x)
        
    def sumVariables(cpu):
        
        x = cpu.getVariable("x")
        y = cpu.getVariable("y")
        cpu.setVariable("z", x + y)
        print(cpu.getVariable("z"))
    
    io = IOInstruction(3)
    cpuvarx = CPUInstruction(defineVariable1, 1)
    cpuvary = CPUInstruction(defineVariable2, 1)
    cpuvarv = CPUInstruction(printeable, 4)
    cpuvarw = CPUInstruction(printeable, 10)
    cpuvarz = CPUInstruction(sumVariables, 1)
    cpusumvar = CPUInstruction(sumVariables)
    cpuresult = CPUInstruction(getVariableResult)
    #cpui2 = CPUInstruction(3)
    #cpui3 = CPUInstruction()
    settingvariables = Program([cpuvarx, cpuvary],1)
    #settingvariables2 = Program([cpuvarz],2)
    settingvariables3 = Program([cpuvarv, cpuvarw],2)
    settingresult = Program([cpuvarz], 4)
    gettingresult = Program([cpuresult],1)
    #program3 = Program([cpui3],5)
    time=Timer(3)
    plan =FIFO()
    sched = Scheduler(plan)
    adj = FirstAdjustment()
    
    
    memory = Memory(512)
    allo = Pagination(6,memory)
    mmu = MMU(allo, memory)
    os = OperatingSystem(mmu, sched,time)
    sched.setOS(os)
    mmu.setOS(os)
    
   
   

    os.executeProgram(settingvariables)
    os.executeProgram(settingvariables3)
    os.executeProgram(settingresult)
    #os.exitOS(0)
    #print(memory.memory)
    #print(allo.usedBlocks)
    #print(allo.unusedBlocks)
    #print(allo.assignationTable)
    #print(os.readyQ)
    os.start()